package com.gonsin.gview.example.bean;


import com.gonsin.gview.annotations.GView;
import com.gonsin.gview.annotations.board.GBoard;
import com.gonsin.gview.annotations.board.GButton;
import com.gonsin.gview.annotations.board.form.*;
import com.gonsin.gview.annotations.board.table.*;
import com.gonsin.gview.annotations.data.*;
import com.gonsin.gview.annotations.enums.ButtonAction;
import com.gonsin.gview.annotations.enums.ColumnType;
import com.gonsin.gview.annotations.enums.InputType;
import com.gonsin.gview.example.actions.*;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

import javax.persistence.*;

import java.util.List;

import static com.gonsin.gview.annotations.enums.ButtonAction.CLOSE_DIALOG;
import static com.gonsin.gview.annotations.enums.ButtonAction.CONFIRM_AND_CLOSE;




@Data
@ApiModel("用户信息")
@Entity
@Table(name = "temp_gs_user")
@ToString
public class UserBean {

    @Id
    @ApiModelProperty("主键")
    @Column(name = "id", columnDefinition = "int comment '主键'")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int userId;

    @ApiModelProperty("用户名 即登录账号")
    @Column(name = "username", columnDefinition = "varchar(64) comment '用户名 即登录账号'")
    private String username; //用户名 即登录账号

    @ApiModelProperty("登录密码")
    @Column(name = "password", columnDefinition = "varchar(64) comment '登录密码'")
    private String password;//登录密码

    @ApiModelProperty(value = "盐值 用于加密时使用的摘要", hidden = true)
    @Column(name = "salt", columnDefinition = "varchar(64) comment '盐值 用于加密时使用的摘要'")
    private String salt; //盐值 用于加密时使用的摘要

    @ApiModelProperty("邮箱")
    @Column(name = "email", columnDefinition = "varchar(128) comment '邮箱'")
    private String email;//邮箱

    @ApiModelProperty("手机号码")
    @Column(name = "phone", columnDefinition = "varchar(64) comment '手机号码'")
    private String phone;//手机号码

    @ApiModelProperty("真实姓名")
    @Column(name = "real_name", columnDefinition = "varchar(64) comment '真实姓名'")
    private String realName;//真实姓名

    @ApiModelProperty("标签")
    @Convert(converter = ListStringConverter.class)
    @Column(name = "标签", columnDefinition = "varchar(1024) comment '标签'")
    private List<String> tags;//真实姓名

    @ApiModelProperty("毫秒数")
    @Column(name = "毫秒数", columnDefinition = "bigint(11) comment '毫秒数'")
    private Long delay;//真实姓名

    @ApiModelProperty("头像图片路径")
    @Column(name = "avatar", columnDefinition = "varchar(256) comment '头像图片路径'")
    private String avatar;//头像图片路径


    public static class ListStringConverter implements AttributeConverter<List<String>, String>{

        @Override
        public String convertToDatabaseColumn(List<String> attribute) {
            return new Gson().toJson(attribute);
        }

        @Override
        public List<String> convertToEntityAttribute(String dbData) {
            return new Gson().fromJson(dbData, new TypeToken<List<String>>(){}.getType());
        }
    }

}
